package com.fjwt.gz.mch.ctrl.fans;

import com.alibaba.fastjson2.JSONObject;
import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.core.model.security.GzUserDetails;
import com.fjwt.gz.db.dto.FansOrderVirtualDTO;
import com.fjwt.gz.mch.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.FansOrderVirtualService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/***
 *  用户订单流水---虚拟奖品（直冲）
 */
@Slf4j
@RestController
@RequestMapping("/api/fans/order/virtual")
public class FansOrderVirtualController extends CommonCtrl {

    @Autowired
    private FansOrderVirtualService fansOrderVirtualService;

    @Value("${notify.domain}")
    private String notifyDomain;

    /**
     * 下单
     */
    @PostMapping(value = "/createOrder")
    public ApiRes createOrder() {
        FansOrderVirtualDTO fansOrderVirtualDTO = getObject(FansOrderVirtualDTO.class);
        log.info("权益商城下单接口：/api/fans/order/virtual/createOrder，参数：{}", JSONObject.toJSONString(fansOrderVirtualDTO));

        GzUserDetails currentUser = getCurrentUser();
        fansOrderVirtualDTO.setFansId(currentUser.getFansId());
        fansOrderVirtualDTO.setAppid(currentUser.getAppId());
        fansOrderVirtualDTO.setNotifyDomain(notifyDomain);

        fansOrderVirtualService.createOrder(fansOrderVirtualDTO);

        return ApiRes.ok();
    }

    /**
     * 订单查询
     */
    @PostMapping(value = "/queryOrder")
    public ApiRes queryOrder() {
        FansOrderVirtualDTO fansOrderVirtualDTO = getObject(FansOrderVirtualDTO.class);
        fansOrderVirtualService.queryOrder(fansOrderVirtualDTO);
        return ApiRes.ok();
    }

}

